package cn.bellychang.leetcode.question704;

/**
 * @author ChangLiang
 * @date 2021/3/8
 */
public class Solution {

    public int search(int[] nums, int target) {
        int result = -1;

        int begin = 0;
        int end = nums.length - 1;
        while(true){
            int mid = ((end - begin) >> 2) + begin;
            if(nums[mid]==target){
                result = mid;
                break;
            }else if(nums[mid]<target){
                begin = mid + 1;
            }else{
                end = mid - 1;
            }
            if(begin > end){
                break;
            }
        }
        return result;
    }
}
